<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#btnExport").click(function(){
				top.$.jBox.confirm("确认要导出用户数据吗？","系统提示",function(v,h,f){
					if(v=="ok"){
						$("#searchForm").attr("action","${ctx}/sys/user/export");
						$("#searchForm").submit();
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});
			$("#btnImport").click(function(){
				$.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true}, 
					bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
			});
			
			
		});
		function page(n,s){
			if(n) $("#pageNo").val(n);
			if(s) $("#pageSize").val(s);
			$("#searchForm").attr("action","${ctx}/sys/user/list");
			$("#searchForm").submit();
	    	return false;
	    }
		
		function delFunc(id){
			var param="id="+id;
			var queryLoginName = $('#queryLoginName').val();
			if(queryLoginName!=null && queryLoginName!=''){
				param = param+'&queryLoginName='+queryLoginName;
			}
			confirmx('确认要删除该用户吗？','${ctx}/sys/user/delete?'+param);
		}
		
		function resetPasswordFunc(id){
			var param="id="+id;
			var queryLoginName = $('#queryLoginName').val();
			if(queryLoginName!=null && queryLoginName!=''){
				param = param+'&queryLoginName='+queryLoginName;
			}
			confirmx('确认要重置该用户密码？','${ctx}/sys/user/resetPassword?'+param);
		}
		
		function cancelUserFunc(isCancel,id){
			var param="id="+id;
			var url="";
			var msg="";
			if(isCancel){
				url="${ctx}/sys/user/cancelUser?";
				msg="确认要注销该用户吗？"
			}else{
				url="${ctx}/sys/user/recoveryUser?";
				msg="确认要恢复该用户吗？"
			}
				
			var queryLoginName = $('#queryLoginName').val();
			if(queryLoginName!=null && queryLoginName!=''){
				param = param+'&queryLoginName='+queryLoginName;
			}
			confirmx(msg,url+param);
		}
	</script>
</head>
<body>
	<div id="importBox" class="hide">
		<form id="importForm" action="${ctx}/sys/user/import" method="post" enctype="multipart/form-data"
			class="form-search" style="padding-left:20px;text-align:center;" onsubmit="loading('正在导入，请稍等...');"><br/>
			<input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
			<input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
			<a href="${ctx}/sys/user/import/template">下载模板</a>
		</form>
	</div>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/user/list">用户列表</a></li>
		<shiro:hasPermission name="sys:user:edit">
			<li>
				<a href="${ctx}/sys/user/form">用户添加</a>
			</li>
		</shiro:hasPermission>
	</ul>
	<form:form id="searchForm" modelAttribute="user" action="${ctx}/sys/user/list" method="post" class="breadcrumb form-search ">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<sys:tableSort id="orderBy" name="orderBy" value="${page.orderBy}" callback="page();"/>
		<ul class="ul-form">
			<li>
				<label>用户名：</label>
			 		<form:input path="queryLoginName" htmlEscape="false" maxlength="50" class="input-medium"/>
			</li>
			<li class="btns">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询" onclick="return page();"/>
				<!-- <input id="btnExport" class="btn btn-primary" type="button" value="导出"/>
				<input id="btnImport" class="btn btn-primary" type="button" value="导入"/></li> -->
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<div style="display:none;">
		<sys:message content="${message}"/>
	</div>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>序号</th>
				<th class="sort-column login_name">用户名</th>
				<th class="sort-column name">姓名</th>
				<th>角色</th>
				<th>状态</th>
				<th>所管辖门店</th>
				<th>备注</th><%--<th>角色</th> --%>
				<shiro:hasPermission name="sys:user:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="user" varStatus="stats">
			<tr>
				<td>${stats.index+1}</td>
				<%-- <td>${user.company.name}</td>
				<td>${user.office.name}</td> --%>
				<td><a href="${ctx}/sys/user/form?id=${user.id}">${user.loginName}</a></td>
				<td>${user.name}</td>
				<td>${user.roleName}</td>
				<td>
					<c:choose>
						<c:when test="${user.loginFlag == 1}">
       						正常
    					</c:when>
						<c:otherwise>
        					失效
   					 	</c:otherwise>
					</c:choose>
				</td>
				<td>${user.storeName}</td>
				<td>${user.remarks}</td><%--
				<td>${user.roleNames}</td> --%>
				<shiro:hasPermission name="sys:user:edit">
					<td>
	    				<a href="${ctx}/sys/user/form?id=${user.id}">编辑</a>
	    				<c:choose>
							<c:when test="${user.loginFlag == 1}">
								<a href="javascript:;" onclick="cancelUserFunc(true,'${user.id}')">失效</a>
	       						<%-- <a href="${ctx}/sys/user/cancelUser?id=${user.id}">失效</a> --%>
	    					</c:when>
							<c:otherwise>
								<a href="javascript:;" onclick="cancelUserFunc(false,'${user.id}')">恢复</a>
	        					<%-- <a href="${ctx}/sys/user/recoveryUser?id=${user.id}">恢复</a> --%>
	   					 	</c:otherwise>
						</c:choose>
						<a href="javascript:;" onclick="resetPasswordFunc('${user.id}')">重置密码</a>
	    				<a href="javascript:;" onclick="delFunc('${user.id}')">删除</a>
					</td>
				</shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>